package com.bdqn.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bdqn.mapper.TransactionServiceMapper;
import com.bdqn.model.CaiwuList;
import com.bdqn.model.CustomerBaseInfo;
import com.bdqn.pojo.Temporary;
import com.bdqn.service.TransactionService;

@Service("transactionService")
public class TransactionServiceImpl implements TransactionService{

	@Autowired
	private TransactionServiceMapper transactionServiceMapper;
	
	

	@Transactional(rollbackFor = Exception.class)
	@Override
	public boolean residueMoney(String loginName, float residueMoney, Temporary temporary) {
		String qian=temporary.getMonery(); //钱数量
		Float money=Float.parseFloat(qian);
		//查询客户id
		CustomerBaseInfo userid=transactionServiceMapper.selectId(temporary.getUserName());
		int id=userid.getId();
		
		//返回的id 进行查询
		String option=temporary.getOperationType();
		Integer val=Integer.parseInt(option);
		CaiwuList type=transactionServiceMapper.queryOption(val);
		 String optionType=type.getType();  //交易类型
		String beizhu=loginName+"对  "+temporary.getUserName()+temporary.getRemark();//备注
		Date day=new Date();
		SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String nowTime=df.format(day);
		int row=transactionServiceMapper.insertDates(optionType,id,residueMoney,money,beizhu,nowTime);
		if(row == 1) {
			return true;
		}
		return false;
	}

	@Override
	public boolean updateMoney(Integer customId, float residueMoney) {
		int row =transactionServiceMapper.updateMoney(customId ,residueMoney);
		if(row == 1) {
			return true;
		}
		return false;
	}

}
